package com.sukaiyi.leetcode._1114print_in_order;

import java.util.concurrent.Semaphore;

/**
 * @author sukaiyi
 * @date 2020/06/24
 */
public class Foo {

    private Semaphore oneSemaphore = new Semaphore(0);
    private Semaphore twoSemaphore = new Semaphore(0);

    public Foo() {
    }

    public void first(Runnable printFirst) throws InterruptedException {

        // printFirst.run() outputs "first". Do not change or remove this line.
        printFirst.run();
        oneSemaphore.release();
    }

    public void second(Runnable printSecond) throws InterruptedException {
        oneSemaphore.acquire();
        // printSecond.run() outputs "second". Do not change or remove this line.
        printSecond.run();
        twoSemaphore.release();
    }

    public void third(Runnable printThird) throws InterruptedException {
        twoSemaphore.acquire();
        // printThird.run() outputs "third". Do not change or remove this line.
        printThird.run();
    }
}
